# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do

  # 获取App工程名
def getAppName()
      # 文件夹路径
  realpath = Pathname.new(File.dirname(__FILE__)).realpath

  appName = ""
  Dir.children(File.dirname(realpath)).each { |file|
    if file.include?(".podspec")
      appName = File.basename(file, File.extname(file)).to_s
    end
  }
  return appName
  
end

  desc "unit test"
  lane :test do
    scan(
      workspace: "Example/JWHelperKit.xcworkspace", 
      scheme: "JWHelperKit_Tests", 
      devices: ["iPhone 8"])
    UI.message("Test Succeeded")
  end

  desc "release new version"
  lane :release do |options|

    target_version = options[:version]
    
    appName = options[:name] || getAppName()

    raise "The version is missed." if target_version.nil?

    appName = options[:name] || path

    version_bump_podspec(
      path: "#{appName}.podspec", 
      version_number: target_version)

    git_add(path: ["./#{appName}.podspec", "./fastlane"])
    git_commit(
      path: ["./#{appName}.podspec", "./fastlane"], 
      message: "release #{appName}_#{target_version} version")
    
    add_git_tag tag: target_version
    push_to_git_remote

    ### pod_push

    exec "pod trunk push #{appName}.podspec --allow-warnings --verbose --use-libraries"

    exec "pod repo update"
    
  end





end
